package com.example.e_comm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Vehicle;
import com.example.demo.mapper.VehicleMapper;
import com.example.demo.service.VehicleService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {
    @Override
    public List<Vehicle> getOnlineVehicles() {
        QueryWrapper<Vehicle> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 2)
                .eq("deleted", 0);
        return list(wrapper);
    }
    @Override
    public IPage<Vehicle> getVehiclePage(IPage<Vehicle> page) {
        QueryWrapper<Vehicle> wrapper = new QueryWrapper<>();
        wrapper.eq("deleted", 0); // 未逻辑删除
        return page(page, wrapper);
    }
    @Override
    public Vehicle getVehicleByVin(String vin) {
        QueryWrapper<Vehicle> wrapper = new QueryWrapper<>();
        wrapper.eq("vin", vin)
                .eq("deleted", 0);
        return getOne(wrapper);
    }
    @Override
    public boolean reportVehicleStatus(Vehicle vehicle) {
        vehicle.setLastReportTime(LocalDateTime.now());
        vehicle.setUpdateTime(LocalDateTime.now());
        return saveOrUpdate(vehicle);
    }
}
